package speed2010.matcher.semanticmatching.basics;

import speed2010.matcher.util.OntologyMatcherProperties;
import speed2010.matcher.semanticmatching.basics.ERelation;

public enum ERelation {
	
	NoRelation(null),
	Equivalent(OntologyMatcherProperties.SPEED_URI + "isEquivalentTo"),
	SubConceptOf(OntologyMatcherProperties.SPEED_URI + "isSubConceptOf"),
	SuperConceptOf(OntologyMatcherProperties.SPEED_URI + "isSuperConceptOf"),
	PartOf(OntologyMatcherProperties.SPEED_URI + "isPartOf"),
	WholeOf(OntologyMatcherProperties.SPEED_URI + "isWholeOf"),
	CloseTo(OntologyMatcherProperties.SPEED_URI + "isCloseTo"),
	DisjointWith(OntologyMatcherProperties.SPEED_URI + "isDisjointWith");
	
	private String relationName;
	
	public String getRelationName() {
		return relationName;
	}

	public double getValue() {
		
		double value = 0.0;
		
		if (this.relationName.contains("isEquivalentTo")) {
			value = OntologyMatcherProperties.EQUIVALENT_VALUE;
		} else if (this.relationName.contains("isSubConceptOf")
				|| this.relationName.contains("isSuperConceptOf")) {
			value = OntologyMatcherProperties.GENERALIZATION_VALUE;
		} else if (this.relationName.contains("isPartOf")
				|| this.relationName.contains("isWholeOf")) {
			value = OntologyMatcherProperties.AGGREGATION_VALUE;
		} else if (this.relationName.contains("isCloseTo")) {
			value = OntologyMatcherProperties.CLOSENESS_VALUE;
		}
		
		return value;
	}	

	private ERelation(String relation)
	{
		this.relationName = relation;
	}
	
	public static ERelation create(String predicate){
		ERelation relation = ERelation.NoRelation;
	
		if (predicate.contains("isEquivalentTo")) {
			relation = ERelation.Equivalent;
		} else if (predicate.contains("isSubConceptOf")) {
			relation = ERelation.SubConceptOf;
		} else if (predicate.contains("isSuperConceptOf")) {
			relation = ERelation.SuperConceptOf;
		} else if (predicate.contains("isPartOf")) {
			relation = ERelation.PartOf;
		} else if(predicate.contains("isWholeOf")) {
			relation = ERelation.WholeOf;
		} else if (predicate.contains("isDisjointWith")) {
			relation = ERelation.DisjointWith;
		} else if (predicate.contains("isCloseTo")) {
			relation = ERelation.CloseTo;
		}
		return relation;
	}
	
	public static ERelation getOpositeRelation(ERelation relation)
	{		
		if(relation.equals(ERelation.Equivalent))
		{
			relation = ERelation.Equivalent;
		}else if(relation.equals(ERelation.SubConceptOf))
		{
			relation = ERelation.SuperConceptOf;
		}else if(relation.equals(ERelation.SuperConceptOf))
		{
			relation = ERelation.SubConceptOf;
		}else if(relation.equals(ERelation.PartOf))
		{
			relation = ERelation.WholeOf;
		}else if(relation.equals(ERelation.WholeOf))
		{
			relation = ERelation.PartOf;
		}
		
		return relation;
	}
	
	@Override
	public String toString() {
		
		String str = "";
		
		if(this.relationName != null &&  !this.relationName.equals(""))
		{
			str = this.relationName.split("#")[1];
		}
		else
		{
			str = "No semantic relation";
		}
		
		return str;
	}
	
}
